home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 2.iso / dist / fw_gsl.idb / usr / freeware / info / gsl-ref.info-2.z / gsl-ref.info-2
Text File  |  2000-10-09  |  48KB  |  1,144 lines

  1. This is gsl-ref.info, produced by Makeinfo version 3.12h from
  2. gsl-ref.texi.
  3.  
  4. INFO-DIR-SECTION Scientific software
  5. START-INFO-DIR-ENTRY
  6. * gsl-ref: (gsl-ref).                   GNU Scientific Library - Reference
  7. END-INFO-DIR-ENTRY
  8.  
  9.    This file documents the GNU Scientific Library.
  10.  
  11.    Copyright (C) 1996, 1997, 1998, 1999 The GSL Project.
  12.  
  13.    Permission is granted to make and distribute verbatim copies of this
  14. manual provided the copyright notice and this permission notice are
  15. preserved on all copies.
  16.  
  17.    Permission is granted to copy and distribute modified versions of
  18. this manual under the conditions for verbatim copying, provided that
  19. the entire resulting derived work is distributed under the terms of a
  20. permission notice identical to this one.
  21.  
  22.    Permission is granted to copy and distribute translations of this
  23. manual into another language, under the above conditions for modified
  24. versions, except that this permission notice may be stated in a
  25. translation approved by the Foundation.
  26.  
  27. 
  28. File: gsl-ref.info,  Node: The block struct,  Next: Block allocation,  Prev: Data types,  Up: Vectors and Matrices
  29.  
  30. The block struct
  31. ================
  32.  
  33.    For consistency all memory is allocated through a `gsl_block'
  34. structure.  The structure contains two members, the size of an area of
  35. memory and a pointer to the memory.  The `gsl_block' structure looks
  36. like this,
  37.  
  38.      typedef struct
  39.      {
  40.        size_t size;
  41.        double * data;
  42.      } gsl_block ;
  43.  
  44. Vectors and matrices are made by "slicing" an underlying block. A slice
  45. is a set of elements formed from an initial offset and a combination of
  46. indices and step-sizes. In the case of a matrix the step-size for the
  47. column index represents the row-length.  The step-size for a vector is
  48. known as the "stride".
  49.  
  50.    The functions for allocating and deallocating blocks are defined in
  51. `gsl_block.h'
  52.  
  53. 
  54. File: gsl-ref.info,  Node: Block allocation,  Next: Reading and writing blocks,  Prev: The block struct,  Up: Vectors and Matrices
  55.  
  56. Block allocation
  57. ================
  58.  
  59.    The functions for allocating memory to a block follow the style of
  60. `malloc' and `free'.  In addition they also perform their own error
  61. checking.  If there is insufficient memory available to allocate a
  62. block then the functions call the GSL error handler (with an error
  63. number of `GSL_ENOMEM') in addition to returning a null pointer.  Thus
  64. if you use the library error handler to abort your program then it
  65. isn't necessary to check every `alloc'.
  66.  
  67.  - Function: gsl_block * gsl_block_alloc (size_t N)
  68.      This function allocates memory for a block of N double-precision
  69.      elements, returning a pointer to the block struct.  The block is
  70.      not initialized and so the values of its elements are undefined.
  71.      Use the function `gsl_block_calloc' if you want to ensure that all
  72.      the elements are initialized to zero.
  73.  
  74.      A null pointer is returned if insufficient memory is available to
  75.      create the block.
  76.  
  77.  - Function: gsl_block * gsl_block_calloc (size_t N)
  78.      This function allocates memory for a block and initializes all the
  79.      elements of the block to zero.
  80.  
  81.  - Function: void gsl_block_free (gsl_block * B)
  82.      This function frees the memory used by a block B previously
  83.      allocated with `gsl_block_alloc' or `gsl_block_calloc'.
  84.  
  85. 
  86. File: gsl-ref.info,  Node: Reading and writing blocks,  Next: Example programs for blocks,  Prev: Block allocation,  Up: Vectors and Matrices
  87.  
  88. Reading and writing blocks
  89. ==========================
  90.  
  91.    The library provides functions for reading and writing blocks to a
  92. file as binary data or formatted text.
  93.  
  94.  - Function: int gsl_block_fwrite (FILE * STREAM, const gsl_block * B)
  95.      This function writes the elements of the block B to the stream
  96.      STREAM in binary format.  The return value is 0 for success and
  97.      `GSL_EFAILED' if there was a problem writing to the file.  Since
  98.      the data is written in the native binary format it may not be
  99.      portable between different architectures.
  100.  
  101.  - Function: int gsl_block_fread (FILE * STREAM, gsl_block * B)
  102.      This function reads into the block B from the open stream STREAM
  103.      in binary format.  The block B must be preallocated with the
  104.      correct length since the function uses the size of B to determine
  105.      how many bytes to read.  The return value is 0 for success and
  106.      `GSL_EFAILED' if there was a problem reading from the file.  The
  107.      data is assumed to have been written in the native binary format
  108.      on the same architecture.
  109.  
  110.  - Function: int gsl_block_fprintf (FILE * STREAM, const gsl_block * B,
  111.           const char * FORMAT)
  112.      This function writes the elements of the block B line-by-line to
  113.      the stream STREAM using the format specifier FORMAT, which should
  114.      be one of the `%g', `%e' or `%f' formats for floating point
  115.      numbers and `%d' for integers.  The function returns 0 for success
  116.      and `GSL_EFAILED' if there was a problem writing to the file.
  117.  
  118.  - Function: int gsl_block_fscanf (FILE * STREAM, gsl_block * B)
  119.      This function reads formatted data from the stream STREAM into the
  120.      block B.  The block B must be preallocated with the correct length
  121.      since the function uses the size of B to determine how many
  122.      numbers to read.  The function returns 0 for success and
  123.      `GSL_EFAILED' if there was a problem reading from the file.
  124.  
  125. 
  126. File: gsl-ref.info,  Node: Example programs for blocks,  Next: The vector struct,  Prev: Reading and writing blocks,  Up: Vectors and Matrices
  127.  
  128. Example programs for blocks
  129. ===========================
  130.  
  131.    The following program shows how to allocate a block,
  132.  
  133.      #include <stdio.h>
  134.      #include <gsl/gsl_block.h>
  135.      
  136.      int main ()
  137.      {
  138.        gsl_block * b = gsl_block_alloc (100) ;
  139.      
  140.        printf("length of block = %u\n", b->size);
  141.        printf("block data address = %#x\n", b->data);
  142.      
  143.        gsl_block_free (b);
  144.      }
  145.  
  146. Here is the output from the program,
  147.  
  148.      length of block = 100
  149.      block data address = 0x804b0d8
  150.  
  151. 
  152. File: gsl-ref.info,  Node: The vector struct,  Next: Vector allocation,  Prev: Example programs for blocks,  Up: Vectors and Matrices
  153.  
  154. The vector struct
  155. =================
  156.  
  157.    Vectors are defined by a `gsl_vector' structure which describes a
  158. slice of a block. A vector represents a "view" of an area of memory,
  159. and different vectors can be created which point to the same block.  For
  160. example, it is possible to make two vectors which point to the even and
  161. odd elements of another vector, or to make vectors which correspond to
  162. the rows and columns of a matrix.
  163.  
  164.    The `gsl_vector' structure contains four members, the "size", the
  165. "stride", a pointer to the memory where the elements are stored, DATA,
  166. and a pointer to the block owned by the vector, BLOCK, if any.  The
  167. structure is very simple and looks like this,
  168.  
  169.      typedef struct
  170.      {
  171.        size_t size;
  172.        size_t stride;
  173.        double * data;
  174.        gsl_block * block;
  175.      } gsl_vector ;
  176.  
  177. The SIZE is simply the number of vector elements.  The range of valid
  178. indices runs from 0 to `size-1'.  The STRIDE is the step-size from one
  179. element to the next in physical memory, measured in units of the
  180. appropriate datatype.  The pointer DATA gives the location of the first
  181. element of the vector in memory.  The pointer BLOCK stores the location
  182. of the memory block owned by the vector (if any).  This block will be
  183. deallocated when the vector is freed.  If the vector is only a view of
  184. another object then the pointer BLOCK is null.
  185.  
  186.    The functions for allocating and accessing vectors are defined in
  187. `gsl_vector.h'
  188.  
  189. 
  190. File: gsl-ref.info,  Node: Vector allocation,  Next: Accessing vector elements,  Prev: The vector struct,  Up: Vectors and Matrices
  191.  
  192. Vector allocation
  193. =================
  194.  
  195.    The functions for allocating memory to a vector follow the style of
  196. `malloc' and `free'.  In addition they also perform their own error
  197. checking.  If there is insufficient memory available to allocate a
  198. vector then the functions call the GSL error handler (with an error
  199. number of `GSL_ENOMEM') in addition to returning a null pointer.  Thus
  200. if you use the library error handler to abort your program then it
  201. isn't necessary to check every `alloc'.
  202.  
  203.  - Function: gsl_vector * gsl_vector_alloc (size_t N)
  204.      This function creates a vector of length N, returning a pointer to
  205.      a newly initialized vector struct. A new block is allocated for the
  206.      elements of the vector, and stored in the BLOCK member of the
  207.      vector struct.  The block is "owned" by the vector, and will be
  208.      deallocated when the vector is deallocated.
  209.  
  210.  - Function: gsl_vector * gsl_vector_calloc (size_t N)
  211.      This function allocates memory for a vector of length N and
  212.      initializes all the elements of the vector to zero.
  213.  
  214.  - Function: void gsl_vector_free (gsl_vector * V)
  215.      This function frees a previously allocated vector V.  If the
  216.      vector was created using `gsl_vector_alloc' then the block
  217.      underlying the vector will also be deallocated.  If the vector has
  218.      been created from another object then the memory is still owned by
  219.      that object and will not be deallocated.
  220.  
  221. 
  222. File: gsl-ref.info,  Node: Accessing vector elements,  Next: Initializing vector elements,  Prev: Vector allocation,  Up: Vectors and Matrices
  223.  
  224. Accessing vector elements
  225. =========================
  226.  
  227.    Unlike FORTRAN compilers, C compilers do not usually provide support
  228. for range checking of vectors and matrices (1).  However, the functions
  229. `gsl_vector_get' and `gsl_vector_set' can perform range checking for
  230. you and report an error if you attempt to access elements outside the
  231. allowed range.
  232.  
  233.    The functions for accessing the elements of a vector or matrix are
  234. defined in `gsl_vector.h' and declared `extern inline' to eliminate
  235. function-call overhead.  If necessary you can turn off range checking
  236. completely without modifying any source files by recompiling your
  237. program with the preprocessor definition `GSL_RANGE_CHECK_OFF'.
  238. Provided your compiler supports inline functions the effect of turning
  239. off range checking is to replace calls to `gsl_vector_get(v,i)' by
  240. `v->data[i*v->stride]' and and calls to `gsl_vector_set(v,i,x)' by
  241. `v->data[i*v->stride]=x'.  Thus there should be no performance penalty
  242. for using the range checking functions when range checking is turned
  243. off.
  244.  
  245.  - Function: double gsl_vector_get (const gsl_vector * V, size_t I)
  246.      This function returns the I-th element of a vector V.  If I lies
  247.      outside the allowed range of 0 to N-1 then the error handler is
  248.      invoked and 0 is returned.
  249.  
  250.  - Function: void gsl_vector_set (gsl_vector * V, size_t I, double X)
  251.      This function sets the value of the I-th element of a vector V to
  252.      X.  If I lies outside the allowed range of 0 to N-1 then the error
  253.      handler is invoked.
  254.  
  255.    ---------- Footnotes ----------
  256.  
  257.    (1) Range checking is available in the GNU C Compiler extension
  258. `checkergcc', as part of its full memory checking facility
  259.  
  260. 
  261. File: gsl-ref.info,  Node: Initializing vector elements,  Next: Reading and writing vectors,  Prev: Accessing vector elements,  Up: Vectors and Matrices
  262.  
  263. Initializing vector elements
  264. ============================
  265.  
  266.  - Function: void gsl_vector_set_all (gsl_vector * V, double X)
  267.      This function sets all the elements of the vector V to the value X.
  268.  
  269.  - Function: void gsl_vector_set_zero (gsl_vector * V)
  270.      This function sets all the elements of the vector V to zero.
  271.  
  272.  - Function: int gsl_vector_set_basis (gsl_vector * V, size_t I)
  273.      This function makes a basis vector by setting all the elements of
  274.      the vector V to zero except for the I-th element which is set to
  275.      one.
  276.  
  277. 
  278. File: gsl-ref.info,  Node: Reading and writing vectors,  Next: Creating subvector views,  Prev: Initializing vector elements,  Up: Vectors and Matrices
  279.  
  280. Reading and writing vectors
  281. ===========================
  282.  
  283.    The library provides functions for reading and writing vectors to a
  284. file as binary data or formatted text.
  285.  
  286.  - Function: int gsl_vector_fwrite (FILE * STREAM, const gsl_vector * V)
  287.      This function writes the elements of the vector V to the stream
  288.      STREAM in binary format.  The return value is 0 for success and
  289.      `GSL_EFAILED' if there was a problem writing to the file.  Since
  290.      the data is written in the native binary format it may not be
  291.      portable between different architectures.
  292.  
  293.  - Function: int gsl_vector_fread (FILE * STREAM, gsl_vector * V)
  294.      This function reads into the vector V from the open stream STREAM
  295.      in binary format.  The vector V must be preallocated with the
  296.      correct length since the function uses the size of V to determine
  297.      how many bytes to read.  The return value is 0 for success and
  298.      `GSL_EFAILED' if there was a problem reading from the file.  The
  299.      data is assumed to have been written in the native binary format
  300.      on the same architecture.
  301.  
  302.  - Function: int gsl_vector_fprintf (FILE * STREAM, const gsl_vector *
  303.           V, const char * FORMAT)
  304.      This function writes the elements of the vector V line-by-line to
  305.      the stream STREAM using the format specifier FORMAT, which should
  306.      be one of the `%g', `%e' or `%f' formats for floating point
  307.      numbers and `%d' for integers.  The function returns 0 for success
  308.      and `GSL_EFAILED' if there was a problem writing to the file.
  309.  
  310.  - Function: int gsl_vector_fscanf (FILE * STREAM, gsl_vector * V)
  311.      This function reads formatted data from the stream STREAM into the
  312.      vector V.  The vector V must be preallocated with the correct
  313.      length since the function uses the size of V to determine how many
  314.      numbers to read.  The function returns 0 for success and
  315.      `GSL_EFAILED' if there was a problem reading from the file.
  316.  
  317. 
  318. File: gsl-ref.info,  Node: Creating subvector views,  Next: Copying vectors,  Prev: Reading and writing vectors,  Up: Vectors and Matrices
  319.  
  320. Creating subvector views
  321. ========================
  322.  
  323.  - Function: gsl_vector gsl_vector_subvector (gsl_vector *V, size_t I,
  324.           size_t N)
  325.      This function returns a `gsl_vector' struct which is a view of a
  326.      subvector of another vector V.  The start of the new vector is
  327.      offset by OFFSET elements from the start of the original vector.
  328.      The new vector has N elements.  Mathematically, the I-th element
  329.      of the new vector V' is given by,
  330.  
  331.           v'(i) = v->data[(offset + i)*v->stride]
  332.  
  333.      where the index I runs from 0 to `n-1'.
  334.  
  335.      The `data' pointer of the returned vector struct is set to null if
  336.      the combined parameters (OFFSET,N) overrun the end of the original
  337.      vector.
  338.  
  339.      The new vector is only a view of the block underlying the original
  340.      vector, V.  The block containing the elements of V is not owned by
  341.      the new vector.  When the new vector goes out of scope the
  342.      original vector V and its block will continue to exist.  The
  343.      original memory can only be deallocated by freeing the original
  344.      vector.  Of course, the original vector should not be deallocated
  345.      while the new vector is still in use.
  346.  
  347.  - Function: gsl_vector gsl_vector_subvector_with_stride (gsl_vector
  348.           *V, size_t I, size_t N, size_t STRIDE)
  349.      This function returns a `gsl_vector' struct which is a view of a
  350.      subvector of another vector V. The subvector is formed in the same
  351.      way as for `gsl_vector_subvector' but with an additional stride
  352.      argument. The new vector has N elements, with a step-size of
  353.      STRIDE from one element to the next in the original vector.
  354.      Mathematically, the I-th element of the new vector V' is given by,
  355.  
  356.           v'(i) = v->data[(offset + i*stride)*v->stride]
  357.  
  358.      where the index I runs from 0 to `n-1'.
  359.  
  360. Note that subvector views give direct access to the underlying elements
  361. of the original vector. For example, the following code will zero the
  362. even elements of the vector `v' of length `n', while leaving the odd
  363. elements untouched,
  364.  
  365.      gsl_vector v_even = gsl_vector_subvector_with_stride (v, 0, n/2, 2);
  366.      gsl_vector_set_zero (&v_even);
  367.  
  368. A vector view can be passed to any subroutine which takes a vector
  369. argument, using the `&' operator, just as a directly allocated vector
  370. would be.  For example, the following code computes the norm of odd
  371. elements of `v' using the BLAS routine DNRM2,
  372.  
  373.      gsl_vector v_odd = gsl_vector_subvector_with_stride (v, 1, n/2, 2);
  374.      double r = gsl_blas_dnrm2 (&v_odd);
  375.  
  376. 
  377. File: gsl-ref.info,  Node: Copying vectors,  Next: Exchanging elements,  Prev: Creating subvector views,  Up: Vectors and Matrices
  378.  
  379. Copying vectors
  380. ===============
  381.  
  382.    Common operations on vectors such as addition and multiplication are
  383. available in the BLAS part of the library (*note BLAS Support::.).
  384. However, it is useful to have a small number of utility functions which
  385. do not require the full BLAS code.  The following functions fall into
  386. this category.
  387.  
  388.  - Function: int gsl_vector_memcpy (gsl_vector * DEST, const gsl_vector
  389.           * SRC)
  390.      This function copies the elements of the vector SRC into the
  391.      vector DEST.  The two vectors must be the same length.
  392.  
  393.  - Function: int gsl_vector_swap (gsl_vector * V, gsl_vector * W)
  394.      This function exchanges the elements of the vectors V and W by
  395.      copying.
  396.  
  397. 
  398. File: gsl-ref.info,  Node: Exchanging elements,  Next: Vector operations,  Prev: Copying vectors,  Up: Vectors and Matrices
  399.  
  400. Exchanging elements
  401. ===================
  402.  
  403.    The following function can be used to exchange, or permute, the
  404. elements of a vector.
  405.  
  406.  - Function: int gsl_vector_swap_elements (gsl_vector * V, size_t i,
  407.           size_t j)
  408.      This function exchanges the I-th and J-th elements of the vector V
  409.      in-place.
  410.  
  411.  - Function: int gsl_vector_reverse (gsl_vector * V)
  412.      This function reverses the order of the elements of the vector V.
  413.  
  414. 
  415. File: gsl-ref.info,  Node: Vector operations,  Next: Finding maximum and minimum elements of vectors,  Prev: Exchanging elements,  Up: Vectors and Matrices
  416.  
  417. Vector operations
  418. =================
  419.  
  420.  - Function: int gsl_vector_add (gsl_vector * A, const gsl_vector * B)
  421.      This function adds the elements of vector B to the elements of
  422.      vector A, a'_i = a_i + b_i. The two vectors must have the same
  423.      length.
  424.  
  425.  - Function: int gsl_vector_sub (gsl_vector * A, const gsl_vector * B)
  426.      This function subtracts the elements of vector B from the elements
  427.      of vector A, a'_i = a_i - b_i. The two vectors must have the same
  428.      length.
  429.  
  430.  - Function: int gsl_vector_mul (gsl_vector * A, const gsl_vector * B)
  431.      This function multiplies the elements of vector A by the elements
  432.      of vector B, a'_i = a_i * b_i. The two vectors must have the same
  433.      length.
  434.  
  435.  - Function: int gsl_vector_div (gsl_vector * A, const gsl_vector * B)
  436.      This function divides the elements of vector A by the elements of
  437.      vector B, a'_i = a_i / b_i. The two vectors must have the same
  438.      length.
  439.  
  440.  - Function: int gsl_vector_scale (gsl_vector * A, const double X)
  441.      This function multiplies the elements of vector A by the constant
  442.      factor X, a'_i = x a_i.
  443.  
  444.  - Function: int gsl_vector_add_constant (gsl_vector * A, const double
  445.           X)
  446.      This function adds the constant value X to the elements of the
  447.      vector A, a'_i = a_i + x.
  448.  
  449. 
  450. File: gsl-ref.info,  Node: Finding maximum and minimum elements of vectors,  Next: Vector properties,  Prev: Vector operations,  Up: Vectors and Matrices
  451.  
  452. Finding maximum and minimum elements of vectors
  453. ===============================================
  454.  
  455.  - Function: double gsl_vector_max (const gsl_vector * V)
  456.      This function returns the maximum value in the vector V.
  457.  
  458.  - Function: double gsl_vector_min (const gsl_vector * V)
  459.      This function returns the minimum value in the vector V.
  460.  
  461.  - Function: void gsl_vector_minmax (const gsl_vector * V, double *
  462.           MIN_OUT, double * MAX_OUT)
  463.      This function returns the minimum and maximum values in the vector
  464.      V, storing them in MIN_OUT and MAX_OUT.
  465.  
  466.  - Function: size_t gsl_vector_max_index (const gsl_vector * V)
  467.      This function returns the index of the maximum value in the vector
  468.      V.  When there are several equal maximum elements then the lowest
  469.      index is returned.
  470.  
  471.  - Function: size_t gsl_vector_min_index (const gsl_vector * V)
  472.      This function returns the index of the minimum value in the vector
  473.      V.  When there are several equal minimum elements then the lowest
  474.      index is returned.
  475.  
  476.  - Function: void gsl_vector_minmax_index (const gsl_vector * V, size_t
  477.           * IMIN, size_t * IMAX)
  478.      This function returns the indices of the minimum and maximum
  479.      values in the vector V, storing them in IMIN and IMAX. When there
  480.      are several equal minimum or maximum elements then the lowest
  481.      indices are returned.
  482.  
  483. 
  484. File: gsl-ref.info,  Node: Vector properties,  Next: Example programs for vectors,  Prev: Finding maximum and minimum elements of vectors,  Up: Vectors and Matrices
  485.  
  486. Vector properties
  487. =================
  488.  
  489.  - Function: int gsl_vector_isnull (const gsl_vector * V)
  490.      This function returns 1 if all the elements of the vector V are
  491.      zero, and 0 otherwise.
  492.  
  493. 
  494. File: gsl-ref.info,  Node: Example programs for vectors,  Next: The matrix struct,  Prev: Vector properties,  Up: Vectors and Matrices
  495.  
  496. Example programs for vectors
  497. ============================
  498.  
  499.    This program shows how to allocate, initialize and read from a vector
  500. using the functions `gsl_vector_alloc', `gsl_vector_set' and
  501. `gsl_vector_get'.
  502.  
  503.      #include <stdio.h>
  504.      #include <gsl/gsl_vector.h>
  505.      
  506.      int main ()
  507.      {
  508.        int i;
  509.        gsl_vector * v = gsl_vector_alloc (3) ;
  510.      
  511.        for (i = 0; i < 3; i++)
  512.          {
  513.            gsl_vector_set (v, i, 1.23 + i);
  514.          }
  515.      
  516.        for (i = 0; i < 100; i++)
  517.          {
  518.            printf("v_%d = %g\n", i, gsl_vector_get (v, i));
  519.          }
  520.      }
  521.  
  522. Here is the output from the program.  The final loop attempts to read
  523. outside the range of the vector `v', and the error is trapped by the
  524. range-checking code in `gsl_vector_get'.
  525.  
  526.      v_0 = 1.23
  527.      v_1 = 2.23
  528.      v_2 = 3.23
  529.      gsl: vector_source.c:12: ERROR: index out of range
  530.      IOT trap/Abort (core dumped)
  531.  
  532. The next program shows how to write a vector to a file.
  533.  
  534.      #include <stdio.h>
  535.      #include <gsl/gsl_vector.h>
  536.      
  537.      int main ()
  538.      {
  539.        int i;
  540.        gsl_vector * v = gsl_vector_alloc (100) ;
  541.      
  542.        for (i = 0; i < 100; i++)
  543.          {
  544.            gsl_vector_set (v, i, 1.23 + i);
  545.          }
  546.      
  547.        {
  548.           FILE * f = fopen("test.dat", "w") ;
  549.           gsl_vector_fprintf (f, v, "%.5g");
  550.           fclose (f);
  551.        }
  552.      }
  553.  
  554. After running this program the file `test.dat' should contain the
  555. elements of `v', written using the format specifier `%.5g'.  The vector
  556. could then be read back in using the function `gsl_vector_fscanf (f,
  557. v)'.
  558.  
  559. 
  560. File: gsl-ref.info,  Node: The matrix struct,  Next: Matrix allocation,  Prev: Example programs for vectors,  Up: Vectors and Matrices
  561.  
  562. The matrix struct
  563. =================
  564.  
  565.    Matrices are defined by a `gsl_matrix' structure which describes a
  566. generalized slice of a block.  Like a vector it represents a "view" of
  567. an area of memory, but uses two indices instead of one.
  568.  
  569.    The `gsl_matrix' structure contains five members, the two dimensions
  570. of the matrix, a physical dimension, a pointer to the memory where the
  571. elements of the matrix are stored, DATA, and a pointer to the block
  572. owned by the matrix BLOCK, if any.  The physical dimension determines
  573. the memory layout and can differ from the matrix dimension to allow the
  574. use of submatrices.  The `gsl_matrix' structure is very simple and
  575. looks like this,
  576.  
  577.      typedef struct
  578.      {
  579.        size_t size1;
  580.        size_t size2;
  581.        size_t tda;
  582.        double * data;
  583.        gsl_block * block;
  584.      } gsl_matrix ;
  585.  
  586. Matrices are stored in row-major order, meaning that each row of
  587. elements forms a contiguous block in memory.  This is the standard
  588. "C-ordering" of two-dimensional arrays. Note that FORTRAN stores arrays
  589. in column-major order. The number of rows is SIZE1.  The range of valid
  590. row indices runs from 0 to `size1-1'.  Similarly SIZE2 is the number of
  591. columns.  The range of valid column indices runs from 0 to `size2-1'.
  592. The physical row dimension TDA, or "trailing dimension", specifies the
  593. size of a row of the matrix as laid out in memory.
  594.  
  595.    For example, in the following matrix SIZE1 is 3, SIZE2 is 4, and TDA
  596. is 8.  The physical memory layout of the matrix begins in the top left
  597. hand-corner and proceeds from left to right along each row in turn.
  598.  
  599.      00 01 02 03 XX XX XX XX
  600.      10 11 12 13 XX XX XX XX
  601.      20 21 22 23 XX XX XX XX
  602.  
  603. Each unused memory location is represented by "`XX'".  The pointer DATA
  604. gives the location of the first element of the matrix in memory.  The
  605. pointer BLOCK stores the location of the memory block owned by the
  606. matrix (if any).  This block will be deallocated when the matrix is
  607. freed.  If the matrix is only a view of another object then the pointer
  608. BLOCK is null.
  609.  
  610.    The functions for allocating and accessing matrices are defined in
  611. `gsl_matrix.h'
  612.  
  613. 
  614. File: gsl-ref.info,  Node: Matrix allocation,  Next: Accessing matrix elements,  Prev: The matrix struct,  Up: Vectors and Matrices
  615.  
  616. Matrix allocation
  617. =================
  618.  
  619.    The functions for allocating memory to a matrix follow the style of
  620. `malloc' and `free'.  They also perform their own error checking.  If
  621. there is insufficient memory available to allocate a vector then the
  622. functions call the GSL error handler (with an error number of
  623. `GSL_ENOMEM') in addition to returning a null pointer.  Thus if you use
  624. the library error handler to abort your program then it isn't necessary
  625. to check every `alloc'.
  626.  
  627.  - Function: gsl_matrix * gsl_matrix_alloc (size_t N1, size_t N2)
  628.      This function creates a matrix of size N1 rows by N2 columns,
  629.      returning a pointer to a newly initialized matrix struct. A new
  630.      block is allocated for the elements of the matrix, and stored in
  631.      the BLOCK member of the matrix struct.  The block is "owned" by the
  632.      matrix, and will be deallocated when the matrix is deallocated.
  633.  
  634.  - Function: gsl_matrix * gsl_matrix_calloc (size_t N1, size_t N2)
  635.      This function allocates memory for a matrix of size N1 rows by N2
  636.      columns and initializes all the elements of the matrix to zero.
  637.  
  638.  - Function: void gsl_matrix_free (gsl_matrix * M)
  639.      This function frees a previously allocated matrix M.  If the
  640.      matrix was created using `gsl_matrix_alloc' then the block
  641.      underlying the matrix will also be deallocated.  If the matrix has
  642.      been created from another object then the memory is still owned by
  643.      that object and will not be deallocated.
  644.  
  645. 
  646. File: gsl-ref.info,  Node: Accessing matrix elements,  Next: Initializing matrix elements,  Prev: Matrix allocation,  Up: Vectors and Matrices
  647.  
  648. Accessing matrix elements
  649. =========================
  650.  
  651.    The functions for accessing the elements of a matrix use the same
  652. range checking system as vectors.  You turn off range checking by
  653. recompiling your program with the preprocessor definition
  654. `GSL_RANGE_CHECK_OFF'.
  655.  
  656.    The elements of the matrix are stored in "C-order", where the second
  657. index moves continuously through memory.  More precisely, the element
  658. accessed by the function `gsl_matrix_get(m,i,j)' and
  659. `gsl_matrix_set(m,i,j,x)' is
  660.  
  661.      m->data[i * m->tda + j]
  662.  
  663. where TDA is the physical row-length of the matrix.
  664.  
  665.  - Function: double gsl_matrix_get (const gsl_matrix * M, size_t I,
  666.           size_t J)
  667.      These functions return the (I,J)th element of a matrix M.  If I or
  668.      J lie outside the allowed range of 0 to N1-1 and 0 to N2-1 then
  669.      the error handler is invoked and 0 is returned.
  670.  
  671.  - Function: void gsl_matrix_set (gsl_matrix * M, size_t I, size_t J,
  672.           double X)
  673.      These functions set the value of the (I,J)th element of a matrix M
  674.      to X.  If I or J lies outside the allowed range of 0 to N1-1 and 0
  675.      to N2-1 then the error handler is invoked.
  676.  
  677. 
  678. File: gsl-ref.info,  Node: Initializing matrix elements,  Next: Reading and writing matrices,  Prev: Accessing matrix elements,  Up: Vectors and Matrices
  679.  
  680. Initializing matrix elements
  681. ============================
  682.  
  683.  - Function: void gsl_matrix_set_all (gsl_matrix * M, double X)
  684.      This function sets all the elements of the matrix M to the value X.
  685.  
  686.  - Function: void gsl_matrix_set_zero (gsl_matrix * M)
  687.      This function sets all the elements of the matrix M to zero.
  688.  
  689.  - Function: void gsl_matrix_set_identity (gsl_matrix * M)
  690.      This function sets the elements of the matrix M to the
  691.      corresponding elements of the identity matrix, m(i,j) =
  692.      \delta(i,j), i.e. a unit diagonal with all off-diagonal elements
  693.      zero.  This applies to both square and rectangular matrices.
  694.  
  695. 
  696. File: gsl-ref.info,  Node: Reading and writing matrices,  Next: Creating submatrix views,  Prev: Initializing matrix elements,  Up: Vectors and Matrices
  697.  
  698. Reading and writing matrices
  699. ============================
  700.  
  701.    The library provides functions for reading and writing matrices to a
  702. file as binary data or formatted text.
  703.  
  704.  - Function: int gsl_matrix_fwrite (FILE * STREAM, const gsl_matrix * M)
  705.      This function writes the elements of the matrix M to the stream
  706.      STREAM in binary format.  The return value is 0 for success and
  707.      `GSL_EFAILED' if there was a problem writing to the file.  Since
  708.      the data is written in the native binary format it may not be
  709.      portable between different architectures.
  710.  
  711.  - Function: int gsl_matrix_fread (FILE * STREAM, gsl_matrix * M)
  712.      This function reads into the matrix M from the open stream STREAM
  713.      in binary format.  The matrix M must be preallocated with the
  714.      correct dimensions since the function uses the size of M to
  715.      determine how many bytes to read.  The return value is 0 for
  716.      success and `GSL_EFAILED' if there was a problem reading from the
  717.      file.  The data is assumed to have been written in the native
  718.      binary format on the same architecture.
  719.  
  720.  - Function: int gsl_matrix_fprintf (FILE * STREAM, const gsl_matrix *
  721.           M, const char * FORMAT)
  722.      This function writes the elements of the matrix M line-by-line to
  723.      the stream STREAM using the format specifier FORMAT, which should
  724.      be one of the `%g', `%e' or `%f' formats for floating point
  725.      numbers and `%d' for integers.  The function returns 0 for success
  726.      and `GSL_EFAILED' if there was a problem writing to the file.
  727.  
  728.  - Function: int gsl_matrix_fscanf (FILE * STREAM, gsl_matrix * M)
  729.      This function reads formatted data from the stream STREAM into the
  730.      matrix M.  The matrix M must be preallocated with the correct
  731.      dimensions since the function uses the size of M to determine how
  732.      many numbers to read.  The function returns 0 for success and
  733.      `GSL_EFAILED' if there was a problem reading from the file.
  734.  
  735. 
  736. File: gsl-ref.info,  Node: Creating submatrix views,  Next: Creating row and column views,  Prev: Reading and writing matrices,  Up: Vectors and Matrices
  737.  
  738. Creating submatrix views
  739. ========================
  740.  
  741.  - Function: gsl_matrix gsl_matrix_submatrix (gsl_matrix * M, size_t I,
  742.           size_t J, size_t N1, size_t N2)
  743.      This function returns a `gsl_matrix' struct which is a view of a
  744.      submatrix of the matrix M.  The upper-left element of the
  745.      submatrix is the element (K1,K2) of the original matrix.  The
  746.      submatrix has N1 rows and N2 columns.  The physical number of
  747.      columns in memory given by TDA is unchanged.  Mathematically, the
  748.      (I,J)-th element of the new matrix is given by,
  749.  
  750.           m'(i,j) = m->data[(k1*m->tda + k2) + i*m->tda + j]
  751.  
  752.      where the index I runs from 0 to `n1-1' and the index J runs from
  753.      0 to `n2-1'.
  754.  
  755.      The `data' pointer of the returned matrix struct is set to null if
  756.      the combined parameters (K1,K2,N1,N2,TDA) overrun the ends of the
  757.      original matrix.
  758.  
  759.      The new matrix is only a view of the block underlying the existing
  760.      matrix, M.  The block containing the elements of M is not owned by
  761.      the new matrix.  When the new matrix goes out of scope the
  762.      original matrix M and its block will continue to exist.  The
  763.      original memory can only be deallocated by freeing the original
  764.      matrix.  Of course, the original matrix should not be deallocated
  765.      while the new matrix is still in use.
  766.  
  767. 
  768. File: gsl-ref.info,  Node: Creating row and column views,  Next: Copying matrices,  Prev: Creating submatrix views,  Up: Vectors and Matrices
  769.  
  770. Creating row and column views
  771. =============================
  772.  
  773.    In general there are two ways to access an object, by reference or by
  774. copying.  The functions described in this section create vectors which
  775. allow access to a row or column of a matrix by reference.  Modifying
  776. elements of the vector is equivalent to modifying the matrix, since both
  777. the vector and the matrix point to the same memory block.
  778.  
  779.  - Function: gsl_vector gsl_matrix_row (gsl_matrix * M, size_t I)
  780.      This function returns `gsl_vector' struct which is a view of the
  781.      I-th row of the matrix M.  The `data' pointer of the new vector is
  782.      set to null if I is out of range.
  783.  
  784.  - Function: gsl_vector gsl_matrix_column (gsl_matrix * M, size_t J)
  785.      This function returns a `gsl_vector' struct which is a view of the
  786.      J-th column of the matrix M.  The `data' pointer of the new vector
  787.      is set to null if J is out of range.
  788.  
  789.  - Function: gsl_vector gsl_matrix_diagonal (gsl_matrix * M)
  790.      This function returns a `gsl_vector' struct which is a view of the
  791.      diagonal of the matrix M. The matrix M is not required to be
  792.      square. For a rectangular matrix the length of the diagonal is the
  793.      same as the smaller dimension of the matrix.
  794.  
  795. 
  796. File: gsl-ref.info,  Node: Copying matrices,  Next: Copying rows and columns,  Prev: Creating row and column views,  Up: Vectors and Matrices
  797.  
  798. Copying matrices
  799. ================
  800.  
  801.  - Function: int gsl_matrix_memcpy (gsl_matrix * DEST, const gsl_matrix
  802.           * SRC)
  803.      This function copies the elements of the matrix SRC into the
  804.      matrix DEST.  The two matrices must have the same size.
  805.  
  806.  - Function: int gsl_matrix_swap (gsl_matrix * M1, const gsl_matrix *
  807.           M2)
  808.      This function exchanges the elements of the matrices M1 and M2 by
  809.      copying.  The two matrices must have the same size.
  810.  
  811. 
  812. File: gsl-ref.info,  Node: Copying rows and columns,  Next: Exchanging rows and columns,  Prev: Copying matrices,  Up: Vectors and Matrices
  813.  
  814. Copying rows and columns
  815. ========================
  816.  
  817.    The functions described in this section copy a row or column of a
  818. matrix into a vector.  This allows the elements of the vector and the
  819. matrix to be modified independently.  Note that if the matrix and the
  820. vector point to overlapping regions of memory then the result will be
  821. undefined.
  822.  
  823.  - Function: int gsl_matrix_get_row (gsl_vector * V, const gsl_matrix *
  824.           M, size_t I)
  825.      This function copies the elements of the I-th row of the matrix M
  826.      into the vector V.  The length of the vector must be the same as
  827.      the length of the row.
  828.  
  829.  - Function: int gsl_matrix_get_col (gsl_vector * V, const gsl_matrix *
  830.           M, size_t J)
  831.      This function copies the elements of the I-th column of the matrix
  832.      M into the vector V.  The length of the vector must be the same as
  833.      the length of the column.
  834.  
  835.  - Function: int gsl_matrix_set_row (gsl_matrix * M, size_t I, const
  836.           gsl_vector * V)
  837.      This function copies the elements of the vector V into the I-th
  838.      row of the matrix M.  The length of the vector must be the same as
  839.      the length of the row.
  840.  
  841.  - Function: int gsl_matrix_set_col (gsl_matrix * M, size_t J, const
  842.           gsl_vector * V)
  843.      This function copies the elements of the vector V into the I-th
  844.      column of the matrix M.  The length of the vector must be the same
  845.      as the length of the column.
  846.  
  847. 
  848. File: gsl-ref.info,  Node: Exchanging rows and columns,  Next: Matrix operations,  Prev: Copying rows and columns,  Up: Vectors and Matrices
  849.  
  850. Exchanging rows and columns
  851. ===========================
  852.  
  853.    The following functions can be used to exchange the rows and columns
  854. of a matrix.
  855.  
  856.  - Function: int gsl_matrix_swap_rows (gsl_matrix * M, size_t I, size_t
  857.           J)
  858.      This function exchanges the I-th and J-th rows of the matrix M
  859.      in-place.
  860.  
  861.  - Function: int gsl_matrix_swap_columns (gsl_matrix * M, size_t I,
  862.           size_t J)
  863.      This function exchanges the I-th and J-th columns of the matrix M
  864.      in-place.
  865.  
  866.  - Function: int gsl_matrix_swap_rowcol (gsl_matrix * M, size_t I,
  867.           size_t J)
  868.      This function exchanges the I-th row and J-th column of the matrix
  869.      M in-place.  The matrix must be square for this operation to be
  870.      possible.
  871.  
  872.  - Function: int gsl_matrix_transpose (gsl_matrix * M)
  873.      This function replaces the matrix M by its transpose by copying
  874.      the elements of the matrix in-place.  The matrix must be square
  875.      for this operation to be possible.
  876.  
  877. 
  878. File: gsl-ref.info,  Node: Matrix operations,  Next: Finding maximum and minimum elements of matrices,  Prev: Exchanging rows and columns,  Up: Vectors and Matrices
  879.  
  880. Matrix operations
  881. =================
  882.  
  883.  - Function: int gsl_matrix_add (gsl_matrix * A, const gsl_matrix * B)
  884.      This function adds the elements of matrix B to the elements of
  885.      matrix A, a'(i,j) = a(i,j) + b(i,j). The two matrices must have the
  886.      same dimensions.
  887.  
  888.  - Function: int gsl_matrix_sub (gsl_matrix * A, const gsl_matrix * B)
  889.      This function subtracts the elements of matrix B from the elements
  890.      of matrix A, a'(i,j) = a(i,j) - b(i,j). The two matrices must have
  891.      the same dimensions.
  892.  
  893.  - Function: int gsl_matrix_mul (gsl_matrix * A, const gsl_matrix * B)
  894.      This function multiplies the elements of matrix A by the elements
  895.      of matrix B, a'(i,j) = a(i,j) * b(i,j). The two matrices must have
  896.      the same dimensions.
  897.  
  898.  - Function: int gsl_matrix_div (gsl_matrix * A, const gsl_matrix * B)
  899.      This function divides the elements of matrix A by the elements of
  900.      matrix B, a'(i,j) = a(i,j) / b(i,j). The two matrices must have the
  901.      same dimensions.
  902.  
  903.  - Function: int gsl_matrix_scale (gsl_matrix * A, const double X)
  904.      This function multiplies the elements of matrix A by the constant
  905.      factor X, a'(i,j) = x a(i,j).
  906.  
  907.  - Function: int gsl_matrix_add_constant (gsl_matrix * A, const double
  908.           X)
  909.      This function adds the constant value X to the elements of the
  910.      matrix A, a'(i,j) = a(i,j) + x.
  911.  
  912. 
  913. File: gsl-ref.info,  Node: Finding maximum and minimum elements of matrices,  Next: Matrix properties,  Prev: Matrix operations,  Up: Vectors and Matrices
  914.  
  915. Finding maximum and minimum elements of matrices
  916. ================================================
  917.  
  918.  - Function: double gsl_matrix_max (const gsl_matrix * M)
  919.      This function returns the maximum value in the matrix M.
  920.  
  921.  - Function: double gsl_matrix_min (const gsl_matrix * M)
  922.      This function returns the minimum value in the matrix M.
  923.  
  924.  - Function: void gsl_matrix_minmax (const gsl_matrix * M, double *
  925.           MIN_OUT, double * MAX_OUT)
  926.      This function returns the minimum and maximum values in the matrix
  927.      M, storing them in MIN_OUT and MAX_OUT.
  928.  
  929.  - Function: void gsl_matrix_max_index (const gsl_matrix * M, size_t *
  930.           IMAX, size_t * JMAX)
  931.      This function returns the indices of the maximum value in the
  932.      matrix M, storing them in IMAX and JMAX.  When there are several
  933.      equal maximum elements then the first element found is returned.
  934.  
  935.  - Function: void gsl_matrix_min_index (const gsl_matrix * M, size_t *
  936.           IMAX, size_t * JMAX)
  937.      This function returns the indices of the minimum value in the
  938.      matrix M, storing them in IMAX and JMAX.  When there are several
  939.      equal minimum elements then the first element found is returned.
  940.  
  941.  - Function: void gsl_matrix_minmax_index (const gsl_matrix * M, size_t
  942.           * IMIN, size_t * IMAX)
  943.      This function returns the indices of the minimum and maximum
  944.      values in the matrix M, storing them in (IMIN,JMIN) and
  945.      (IMAX,JMAX. When there are several equal minimum or maximum
  946.      elements then the first elements found are returned.
  947.  
  948. 
  949. File: gsl-ref.info,  Node: Matrix properties,  Next: Example programs for matrices,  Prev: Finding maximum and minimum elements of matrices,  Up: Vectors and Matrices
  950.  
  951. Matrix properties
  952. =================
  953.  
  954.  - Function: int gsl_matrix_isnull (const gsl_matrix * M)
  955.      This function returns 1 if all the elements of the matrix M are
  956.      zero, and 0 otherwise.
  957.  
  958. 
  959. File: gsl-ref.info,  Node: Example programs for matrices,  Next: Vector and Matrix References and Further Reading,  Prev: Matrix properties,  Up: Vectors and Matrices
  960.  
  961. Example programs for matrices
  962. =============================
  963.  
  964.    This program shows how to allocate, initialize and read from a matrix
  965. using the functions `gsl_matrix_alloc', `gsl_matrix_set' and
  966. `gsl_matrix_get'.
  967.  
  968.      #include <stdio.h>
  969.      #include <gsl/gsl_matrix.h>
  970.      
  971.      int main ()
  972.      {
  973.        int i, j;
  974.        gsl_matrix * m = gsl_matrix_alloc (10, 3) ;
  975.      
  976.        for (i = 0; i < 10; i++)
  977.          for (j = 0; j < 3; j++)
  978.            gsl_matrix_set (m, i, j, 0.23 + 100*i + j);
  979.      
  980.        for (i = 0; i < 100; i++)
  981.          for (j = 0; j < 3; j++)
  982.            printf("m(%d,%d) = %g\n", i, j, gsl_matrix_get (m, i, j));
  983.      }
  984.  
  985. Here is the output from the program.  The final loop attempts to read
  986. outside the range of the matrix `m', and the error is trapped by the
  987. range-checking code in `gsl_matrix_get'.
  988.  
  989.      m(0,0) = 0.23
  990.      m(0,1) = 1.23
  991.      m(0,2) = 2.23
  992.      m(1,0) = 100.23
  993.      m(1,1) = 101.23
  994.      m(1,2) = 102.23
  995.      ...
  996.      m(9,2) = 902.23
  997.      gsl: matrix_source.c:13: ERROR: first index out of range
  998.      IOT trap/Abort (core dumped)
  999.  
  1000. The next program shows how to write a matrix to a file.
  1001.  
  1002.      #include <stdio.h>
  1003.      #include <gsl/gsl_matrix.h>
  1004.      
  1005.      int main ()
  1006.      {
  1007.        int i, j, differences = 0;
  1008.        gsl_matrix * m = gsl_matrix_alloc (100, 100) ;
  1009.        gsl_matrix * a = gsl_matrix_alloc (100, 100) ;
  1010.      
  1011.        for (i = 0; i < 100; i++)
  1012.          for (j = 0 ; j < 100; j++)
  1013.            gsl_matrix_set (m, i, j, 0.23 + i + j);
  1014.      
  1015.        {
  1016.           FILE * f = fopen("test.dat", "w") ;
  1017.           gsl_matrix_fwrite (f, m);
  1018.           fclose (f);
  1019.        }
  1020.      
  1021.        {
  1022.           FILE * f = fopen("test.dat", "r") ;
  1023.           gsl_matrix_fread (f, a);
  1024.           fclose (f);
  1025.        }
  1026.      
  1027.        for (i = 0; i < 100; i++)
  1028.          for (j = 0 ; j < 100; j++)
  1029.              if (gsl_matrix_get(m, i, j) != gsl_matrix_get(a, i, j))
  1030.                 differences ++ ;
  1031.      
  1032.        printf("differences = %d (should be zero)\n", differences) ;
  1033.      
  1034.      }
  1035.  
  1036. After running this program the file `test.dat' should contain the
  1037. elements of `m', written in binary format.  The matrix which is read
  1038. back in using the function `gsl_matrix_fread' should be exactly equal
  1039. to the original matrix.
  1040.  
  1041. 
  1042. File: gsl-ref.info,  Node: Vector and Matrix References and Further Reading,  Prev: Example programs for matrices,  Up: Vectors and Matrices
  1043.  
  1044. References and Further Reading
  1045. ==============================
  1046.  
  1047.    The block, vector and matrix objects in GSL follow the `valarray'
  1048. model of C++.  A description of this model can be found in the following
  1049. reference,
  1050.  
  1051.      B. Stroustrup, `The C++ Programming Language' (3rd Ed), Section
  1052.      22.4 Vector Arithmetic.  Addison-Wesley 1997, ISBN 0-201-88954-4.
  1053.  
  1054. 
  1055. File: gsl-ref.info,  Node: BLAS Support,  Next: Linear Algebra,  Prev: Vectors and Matrices,  Up: Top
  1056.  
  1057. BLAS Support
  1058. ************
  1059.  
  1060. * Menu:
  1061.  
  1062. * Introduction::
  1063. * Organization::
  1064. * GSL BLAS Interface::
  1065. * Raw BLAS Interface::
  1066. * BLAS References and Further Reading::
  1067.  
  1068. 
  1069. File: gsl-ref.info,  Node: Introduction,  Next: Organization,  Up: BLAS Support
  1070.  
  1071. Introduction
  1072. ============
  1073.  
  1074.    The Basic Linear Algebra Standard (BLAS) prescribes a set of
  1075. fundamental operations on vectors and matrices which can be used to
  1076. create higher-level linear algebra functionality.  Because of the many
  1077. possible types of vectors and matrices, including variations in base
  1078. precision, the number of functions specified by the BLAS standard is
  1079. tediously large.
  1080.  
  1081.    Furthermore, because of the long history of BLAS and BLAS-like
  1082. implementations, and the need for interoperability, the complexity of
  1083. this part of GSL is somewhat high.  Casual users will often find what
  1084. they need in the `gsl_linalg' library, which implements a set of common
  1085. high-level linear algebra operations on GSL vector and matrix objects.
  1086. Some familiarity with the BLAS standards, including both the legacy and
  1087. draft interface standards, is assumed in this chapter.
  1088.  
  1089. 
  1090. File: gsl-ref.info,  Node: Organization,  Next: GSL BLAS Interface,  Prev: Introduction,  Up: BLAS Support
  1091.  
  1092. Organization
  1093. ============
  1094.  
  1095.    GSL provides two layers of BLAS functionality, a low-level or "raw"
  1096. layer, which corresponds directly to the BLAS standard, and a GSL
  1097. specific layer for operation on GSL vector and matrix objects.  Users
  1098. who are interested in simple operations on GSL vector and matrix objects
  1099. should use the high-level GSL specific layer, which is specified in the
  1100. file `gsl_blas.h'.  Also, users interested in simple linear algebra
  1101. functionality for GSL vector and matrix objects are directed to the
  1102. `gsl_linalg' library.  This should satisfy the needs of most users.
  1103. Note that full BLAS functionality is not available for GSL vector and
  1104. matrix objects since GSL provides only standard dense storage-format
  1105. objects, for which much of the BLAS functionality does not apply.
  1106.  
  1107.    The interface for the `gsl_blas_raw' layer is specified in the file
  1108. `gsl_blas_raw.h'.  The functionality described by this interface is
  1109. semantically equivalent to the BLAST reference draft for a C interface
  1110. to legacy BLAS implementations.
  1111.  
  1112.    The `gsl_blas_raw' layer exists in order to provide an extra layer
  1113. of indirection over legacy BLAS functionality, so that users have the
  1114. ability to switch BLAS implementations at link time. GSL itself
  1115. provides two implementations conforming to the `gsl_blas_raw'
  1116. interface, each in the form of a compiled library.
  1117.  
  1118.    The first implementation, `libgslblasnative', is a native GSL
  1119. implementation of level-1, level-2, and a portion of level-3
  1120. functionality.  Users who need to use the low-level `gsl_blas_raw'
  1121. functions and who do not have access to a vendor-supplied or other
  1122. CBLAS implementation, or who are not interested in optimal performance,
  1123. can use this native functionality by writing their code to the
  1124. `gsl_blas_raw' interface and linking with `libgslblasnative'.
  1125.  
  1126.    The second provided implementation `libgslblascblas', is a wrapper
  1127. over a conforming CBLAS implementation, which is assumed to exist (and
  1128. which in some cases can be detected at configure time).  Users who have
  1129. access to a conforming CBLAS implementation can use such a library by
  1130. writing their code to the `gsl_blas_raw' interface and linking with
  1131. `libgslblascblas'.  Note that users who have only a legacy Fortran
  1132. source BLAS library will need to first obtain a CBLAS conformant
  1133. wrapper and compile that. A reference CBLAS implementation, written as
  1134. a wrapper over a legacy Fortran implementation, exists as part of the
  1135. draft CBLAS standard and can be obtained via Netlib.
  1136.  
  1137.    Using the extra layer provided by the `gsl_blas_raw' interface,
  1138. users or third-parties can also create their own implementations.  Any
  1139. implementation conforming to the `gsl_blas_raw' interface (or perhaps
  1140. some portion thereof) can be linked against the same client code.  We
  1141. hope that this will provide some insulation for client code against
  1142. arbitrariness in BLAS or BLAS-like implementations.
  1143.  
  1144.